package com.sxt.server.util;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import io.netty.channel.Channel;


/**
 * 工具类把客户端id作为key放入map中 把通道放入对应value，相当于做一个绑定
 * @author Administrator
 *
 */
public class NettySession {
	private static final Map<String, Channel> MAP = new ConcurrentHashMap<>(16);

    public static void put(String id, Channel socketChannel) {
        MAP.put(id, socketChannel);
    }

    public static Channel get(String id) {
        return MAP.get(id);
    }

    public static Map<String, Channel> getMAP() {
        return MAP;
    }

    public static void remove(Channel socketChannel) {
        MAP.entrySet().stream().filter(entry -> entry.getValue() == socketChannel).forEach(entry -> MAP.remove(entry.getKey()));
    }
}
